package br.com.novagalvao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import br.com.novagalvao.beans.Manifesto;
import br.com.novagalvao.enums.EnumCargo;
import br.com.novagalvao.enums.EnumFormaPagamento;
import br.com.novagalvao.services.FuncionarioServices;
import br.com.novagalvao.services.ManifestoServices;


//CRIAR UM VIEW HELPER

@RequestMapping(value="/manifesto")
@Controller
public class ManifestoController {
	
	private static final String CONTEXT_PAGE = "pages";
	
	@Autowired
	private ManifestoServices manifestoServices;
	
	@Autowired
	private FuncionarioServices funcionarioServices;
	
	
	
	
	@RequestMapping(value = "/novo")
	public ModelAndView novo(){
		
		ModelAndView mav = new ModelAndView(CONTEXT_PAGE+"/manifesto/manifesto");
		
		buildCombosManifesto(mav);
		
		return mav; 
	}
	
	
	@RequestMapping(value = "/salvar")
	public String salvar(Manifesto manifesto, Long[] func){
		
		manifestoServices.salvar(manifesto, func);
		
		return "redirect:/manifesto/listar";
	}
	
	
	@RequestMapping(value = "/buscar{id}")
	public String buscar(@PathVariable int id){
		
		new ModelAndView("");
		
		return "";
	}
	
	
	
	@RequestMapping(value = "/listar")
	public ModelAndView listar(){

		ModelAndView view = new ModelAndView(CONTEXT_PAGE+"/manifesto/lista");

		List<Manifesto> manifestos = manifestoServices.listAll();
		view.addObject(manifestos);

		return view;
	}
	
	
	@RequestMapping(value = "/atualizar")
	public String atualizar(){
		return "";
	}
	
	
	@RequestMapping(value = "/excluir")
	public String deletar(){
		return "excluir";
	}
	
	private void buildCombosManifesto(ModelAndView modelAndView){

		modelAndView.addObject("listRepresentantes", funcionarioServices.listFuncionariosByCargo(EnumCargo.REPRESENTANTE));
		modelAndView.addObject("listMotoristas", funcionarioServices.listFuncionariosByCargo(EnumCargo.MOTORISTA));
		modelAndView.addObject("pagamentos", EnumFormaPagamento.values());

	}
	
	
	
}
